package com.smartboard.network.ui;

import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.smartboard.network.R;
import com.smartboard.network.client.GameClient;
import com.smartboard.network.game.IRoom;

/**
 * Created by cheas on 2018/8/23.
 */

public class EnterRoomPasswordDialog extends BaseDialog {
    private IRoom mRoom;
    private EditText mPasswordText;
    private Activity mActivity;

    public EnterRoomPasswordDialog(Activity activity, IRoom room) {
        super(activity);

        mRoom = room;
        mActivity = activity;
        setTitle(R.string.title_enter_room_password);
        setContentView(R.layout.dialog_enter_room_password);
        setCanceledOnTouchOutside(true);

        mPasswordText = (EditText)findViewById(R.id.password);

        Button okBtn = (Button)findViewById(R.id.okBtn);
        Button cancelBtn = (Button)findViewById(R.id.cancenBtn);
        okBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String password = mPasswordText.getText().toString();
                if(password.isEmpty()) {
                    mPasswordText.setError(getContext().getString(R.string.error_field_required));
                    return;
                }
                MyApplication.hideKeyboard(mActivity);
                GameClient.inst().enterRoom(mRoom, password);
            }
        });

        cancelBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        adjustWindowSize();
    }
}
